package com.hpf.lease.web.admin.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hpf.lease.common.config.CommonException;
import com.hpf.lease.common.result.ResultCodeEnum;
import com.hpf.lease.model.bean.SystemPost;
import com.hpf.lease.web.admin.mapper.SystemPostMapper;
import com.hpf.lease.web.admin.service.SystemPostService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
* @author GOD
* @description 针对表【system_post(岗位信息表)】的数据库操作Service实现
* @createDate 2024-08-29 15:00:50
*/
@Service
public class SystemPostServiceImpl extends ServiceImpl<SystemPostMapper, SystemPost>
    implements SystemPostService {

    @Override
    @Transactional
    public boolean saveOrUpdateInfo(SystemPost post) {
        long id = post.getId() == null ? -1L : post.getId();
        SystemPost one = this.getOne(Wrappers.lambdaQuery(SystemPost.class)
                .eq(SystemPost::getPostCode, post.getPostCode())
                .eq(SystemPost::getDeleted, 0)
                .last("limit 1"));
        if (one != null && !one.getId().equals(id)){
            throw  new CommonException(ResultCodeEnum.SYSTEM_POST_EXISTS_ERROR);
        }
        this.saveOrUpdate(post);
        return true;
    }

    @Override
    public Page<SystemPost> getPageItem(Integer current, Integer size) {
        return  baseMapper.selectPage(new Page<>(current, size), null);
    }
}




